/*
 * Graph.h
 *
 *  Created on: Mar 22, 2014
 *      Author: zby
 */

#ifndef GRAPH_H_
#define GRAPH_H_
#include <stdint.h>
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>

using namespace std;

namespace graph {

    typedef int NodeVal;
    typedef unsigned int EdgeVal;
    typedef unsigned int Node;

    class Graph{
        private:
            EdgeVal **ppEdgeMatrix;
            NodeVal *pNodeValue;
            unsigned int Ed;
            unsigned int size;
        public:
            static const unsigned int EdgeInit;
            static const int NodeValueInit;

            Graph(unsigned int size);
            Graph(const Graph &_g);
            virtual ~Graph(void);
            bool AddEdge(Node x, Node y, EdgeVal a);
            bool DeleteEdge(Node x, Node y);
            bool Adjacent(Node x, Node y);
            unsigned int E(void);
            vector<Node>Neighbors(Node k);
            NodeVal Get_node_value(Node k);
            void Set_node_value(Node k, NodeVal a);
            EdgeVal Get_edge_value(Node x, Node y);
            bool Set_edge_value(Node x, Node y, EdgeVal a);
            //----My friends-----------------------------------------------------------:
            friend ostream& operator<<(ostream& _stream,  Graph &_graph){
                vector<Node> vlist;
                for(Node i=0; i<_graph.size; i++)
                {
                    vlist = _graph.Neighbors(i);
                    cout<<"Node: "<<i;
                    for(vector<Node>::iterator it=vlist.begin(); it!=vlist.end(); ++it)
                        cout<<"->"<<*it<<"("<<_graph.ppEdgeMatrix[i][*it]<<")";
                    cout<<endl;
                }
                return _stream;
            }
    };

}
#endif /* GRAPH_H_ */
